# -*- coding: utf-8 -*-
'''
Created on 2012-06-12

@author: alexandre
'''

import sys
sys.stdout = sys.stderr

from os import path
projectDir = path.dirname( __file__ )
sys.path = [projectDir, path.join( projectDir, '..' )] + sys.path

import atexit
import cherrypy
from evalServer import MlEvalServer, garabageCollector, siteFolder
from threading import Timer

expirationDelay = 60 # seconds
gcDelay = 10 # garbage collector delay in seconds



cherrypy.config.update({'environment': 'embedded'})


if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:
    cherrypy.engine.start(blocking=False)
    atexit.register(cherrypy.engine.stop)


config = {'/': {'tools.encode.on': True, 'tools.encode.encoding': "utf-8"}}
cherrypy.response.headers['Content-Type'] = "text/html; charset=utf-8"


timer = Timer(gcDelay, garabageCollector, (siteFolder, expirationDelay,gcDelay) )
timer.start()
application = cherrypy.Application(MlEvalServer(), script_name=None, config=config)
#application = cherrypy.Application(Root(), script_name=None, config=None)